home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Source / GNU / uucp / uucico / time.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-20  |  3.3 KB  |  133 lines

  1. /* time.c
  2.    Routines to deal with UUCP time spans.
  3.  
  4.    Copyright (C) 1991, 1992, 1993 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP package.
  7.  
  8.    This program is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucp.h"
  27.  
  28. #if USE_RCS_ID
  29. const char time_rcsid[] = "$Id: time.c,v 1.21 1995/06/21 19:16:02 ian Rel $";
  30. #endif
  31.  
  32. #include <ctype.h>
  33.  
  34. #if TM_IN_SYS_TIME
  35. #include <sys/time.h>
  36. #else
  37. #include <time.h>
  38. #endif
  39.  
  40. #include "uudefs.h"
  41. #include "uuconf.h"
  42.  
  43. /* External functions.  */
  44. #ifndef time
  45. extern time_t time ();
  46. #endif
  47. #ifndef localtime
  48. extern struct tm *localtime ();
  49. #endif
  50.  
  51. /* See if the current time matches a time span.  If it does, return
  52.    TRUE, set *pival to the value for the matching span, and set
  53.    *pcretry to the retry for the matching span.  Otherwise return
  54.    FALSE.  */
  55.  
  56. boolean
  57. ftimespan_match (qspan, pival, pcretry)
  58.      const struct uuconf_timespan *qspan;
  59.      long *pival;
  60.      int *pcretry;
  61. {
  62.   time_t inow;
  63.   struct tm *qtm;
  64.   int itm;
  65.   const struct uuconf_timespan *q;
  66.  
  67.   if (qspan == NULL)
  68.     return FALSE;
  69.  
  70.   time (&inow);
  71.   qtm = localtime (&inow);
  72.  
  73.   /* Get the number of minutes since Sunday for the time.  */
  74.   itm = qtm->tm_wday * 24 * 60 + qtm->tm_hour * 60 + qtm->tm_min;
  75.  
  76.   for (q = qspan; q != NULL; q = q->uuconf_qnext)
  77.     {
  78.       if (q->uuconf_istart <= itm && itm <= q->uuconf_iend)
  79.     {
  80.       if (pival != NULL)
  81.         *pival = q->uuconf_ival;
  82.       if (pcretry != NULL)
  83.         *pcretry = q->uuconf_cretry;
  84.       return TRUE;
  85.     }
  86.     }
  87.  
  88.   return FALSE;
  89. }
  90.  
  91. /* Determine the maximum size that may ever be transferred, according
  92.    to a timesize span.  This returns -1 if there is no limit.  */
  93.  
  94. long
  95. cmax_size_ever (qtimesize)
  96.      const struct uuconf_timespan *qtimesize;
  97. {
  98.   long imax;
  99.   const struct uuconf_timespan *q;
  100.  
  101.   if (qtimesize == NULL)
  102.     return -1;
  103.  
  104.   /* Look through the list of spans.  If there is any gap larger than
  105.      1 hour, we assume there are no restrictions.  Otherwise we keep
  106.      track of the largest value we see.  I picked 1 hour arbitrarily,
  107.      on the theory that a 1 hour span to transfer large files might
  108.      actually occur, and is probably not an accident.  */
  109.   if (qtimesize->uuconf_istart >= 60)
  110.     return -1;
  111.  
  112.   imax = -1;
  113.  
  114.   for (q = qtimesize; q != NULL; q = q->uuconf_qnext)
  115.     {
  116.       if (q->uuconf_qnext == NULL)
  117.     {
  118.       if (q->uuconf_iend <= 6 * 24 * 60 + 23 * 60)
  119.         return -1;
  120.     }
  121.       else
  122.     {
  123.       if (q->uuconf_iend + 60 <= q->uuconf_qnext->uuconf_istart)
  124.         return -1;
  125.     }
  126.  
  127.       if (imax < q->uuconf_ival)
  128.     imax = q->uuconf_ival;
  129.     }
  130.  
  131.   return imax;
  132. }
  133.